<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        var temp = "";

        function run1(x) {
            var img = document.getElementsByTagName("img");
            for (var i = 0; i < img.length; i++) {
                if (img[i].id <= x.id) {
                    if (x.id <= 2) {
                        img[i].src = "img/b.png"
                    } else {
                        img[i].src = "img/a.png"
                    }
                } else {
                    img[i].src = "img/c.png"
                }
            }
        }

        function run2(x) {
            if (temp == "") {
                var img = document.getElementsByTagName("img");
                for (var i = 0; i < img.length; i++) {
                    img[i].src = "img/c.png";
                }
            } else  {
                var img = document.getElementsByTagName("img");
                for (var i = 0; i < img.length; i++) {
                    if (img[i].id <= temp) {
                        if (temp <= 2) {
                            img[i].src = "img/b.png"
                        } else {
                            img[i].src = "img/a.png"
                        }
                    } else {
                        img[i].src = "img/c.png"
                    }
                }
            }
        }

        function run3(x) {
            if (temp == x.id) {
                temp = "";
                run2(x);
            } else {
                temp = x.id;
                run1(x);
            }
        }

    </script>
</head>
<body>
<img id="1" src="img/c.png" onmouseover="run1(this)" onmouseout="run2(this)" onclick="run3(this)"/>
<img id="2" src="img/c.png" onmouseover="run1(this)" onmouseout="run2(this)" onclick="run3(this)"/>
<img id="3" src="img/c.png" onmouseover="run1(this)" onmouseout="run2(this)" onclick="run3(this)"/>
<img id="4" src="img/c.png" onmouseover="run1(this)" onmouseout="run2(this)" onclick="run3(this)"/>
<img id="5" src="img/c.png" onmouseover="run1(this)" onmouseout="run2(this)" onclick="run3(this)"/>
</body>
</html>